import request from '@/utils/request';

/**
 * 批次管理查询
 */
export async function codegroupSearch(data: API.CodegroupSearchInfo, options?: API.baseOption) {
  return request<API.BasePaginationRes<API.CodegroupListItem>>('/codegroup/search', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
 * 批次管理-生成码
 */
export async function codegroupCreateCoupon(
  data: { id: string; num: number },
  options?: API.baseOption,
) {
  return request<string>('/codegroup/create-coupon', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
 * 批次管理-批量激活
 */
export async function redeemActivateCode(data: API.CodegroupEditInfo, options?: API.baseOption) {
  return request<string>('/codegroup/redeem-activatecode', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
 * 批次管理-导出码
 */
export async function exportCode(data: { id: string }, options?: API.baseOption) {
  return request<any>('/codegroup/export-code', {
    method: 'POST',
    getResponse: true,
    responseType: 'blob',
    data,
    ...(options || {}),
  });
}

/**
 * 批次管理-导出明细
 */
export async function exportDetail(data: { id: string }, options?: API.baseOption) {
  return request<any>('/codegroup/export-detail', {
    getResponse: true,
    method: 'POST',
    responseType: 'blob',
    data,
    ...(options || {}),
  });
}

/**
 * 批次管理-导出
 */
export async function codegroupExport(options?: API.baseOption) {
  return request<any>('/codegroup/export', {
    getResponse: true,
    method: 'POST',
    responseType: 'blob',
    ...(options || {}),
  });
}

/**
 * 批次管理-刷新缓存
 */
export async function codegroupResetTask(options?: API.baseOption) {
  return request<string>('/codegroup/reset-task', {
    method: 'POST',
    ...(options || {}),
  });
}

/**
 * 批次管理编辑
 */
export async function codegroupEdit(data: API.CodegroupEditInfo, options?: API.baseOption) {
  return request<string>('/codegroup/edit', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
 * 2.5.9 批次明细/coupon-config/codegroup/detail
 */
export async function codegroupDetail(data: { id: string }, options?: API.baseOption) {
  return request<API.CodegroupEditInfo>('/codegroup/detail', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
 * 2.5.10 批量销毁/coupon-config/codegroup/batch-destroy
 */
export async function batchDestroy(data: { id: string }, options?: API.baseOption) {
  return request<string>('/codegroup/batch-destroy', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}
